home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 13.6 KB | 487 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGDIObj.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifdef FW_BUILD_WIN
-
- #ifndef FWGDIOBJ_H
- #include "FWGDIObj.h"
- #endif
-
- #ifndef SLGRGLOB_H
- #include "SLGrGlob.h"
- #endif
-
- #ifndef FWODEXCE_H
- #includ "FWODExce.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWCOMMON_H
- #include <FWCommon.h>
- #endif
-
- #ifndef FWEXCDEF_H
- #include <FWExcDef.h>
- #endif
-
- #ifndef FWMEMORY_H
- #include <FWMemory.h>
- #endif
-
- //========================================================================================
- // class FW_CPrivWinGDIObject
- //========================================================================================
-
- FW_DECLARE_AUTO(FW_CPrivWinGDIObject)
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::FW_CPrivWinGDIObject
- //----------------------------------------------------------------------------------------
-
- FW_CPrivWinGDIObject::FW_CPrivWinGDIObject() :
- fGDIObject(),
- fStockID(0xFFFF),
- fStockObject(FALSE),
- fDC(NULL),
- fPreviousObject(NULL),
- fChanged(FALSE)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::~FW_CPrivWinGDIObject
- //----------------------------------------------------------------------------------------
-
- FW_CPrivWinGDIObject::~FW_CPrivWinGDIObject()
- {
- FW_START_DESTRUCTOR
-
- FW_ASSERT(fDC == NULL);
- FW_ASSERT(fPreviousObject == NULL);
- DeleteGDIObject(fGDIObject);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::SetStockID
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinGDIObject::SetStockID(int stockID)
- {
- if (stockID != fStockID || !fStockObject || fGDIObject == NULL)
- {
- fStockID = stockID;
- fStockObject = TRUE;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::UnselectObject
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinGDIObject::UnselectObject(HDC hdc)
- {
- if (fPreviousObject != NULL)
- {
- FW_ASSERT(fDC == hdc);
- FW_ASSERT(fGDIObject != NULL); // We can't have fPreviousObject != NULL and fGDIObject == NULL
-
- ::SelectObject(fDC, fPreviousObject);
- fPreviousObject = NULL;
- fDC = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::DeleteGDIObject
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinGDIObject::DeleteGDIObject(FW_CPrivWinGDIObjectHandle& GDIObject)
- {
- if (GDIObject.fObject != NULL && !GDIObject.fIsStock)
- ::DeleteObject(GDIObject.fObject);
- GDIObject.fObject = NULL;
- GDIObject.fIsStock = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::MakeObject
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivWinGDIObject::MakeGDIObject(FW_CPrivWinGDIObjectHandle& GDIObject)
- {
- GDIObject.fObject = (GDIObject.fIsStock = fStockObject) == TRUE ? ::GetStockObject(fStockID) : CreateObject();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::SelectObject
- //----------------------------------------------------------------------------------------
- // Use to select an object into a DC
-
- void FW_CPrivWinGDIObject::SelectObject(HDC hdc)
- {
- if (fGDIObject == NULL)
- {
- FW_ASSERT(fDC == NULL);
- FW_ASSERT(fPreviousObject == NULL);
- MakeGDIObject(fGDIObject);
- fPreviousObject = ::SelectObject(hdc, fGDIObject);
- FW_ASSERT(fPreviousObject != NULL);
- fDC = hdc;
- fChanged = FALSE;
- }
- else if (fChanged)
- {
- if (fPreviousObject == NULL)
- {
- FW_ASSERT(fDC == NULL);
-
- // ----- We know it is not selected otherwise fPreviousObject would be != NULL -----
- DeleteGDIObject(fGDIObject);
-
- MakeGDIObject(fGDIObject);
-
- fPreviousObject = ::SelectObject(hdc, fGDIObject);
- FW_ASSERT(fPreviousObject != NULL);
- fDC = hdc;
- }
- else
- {
- FW_ASSERT(fDC == hdc);
-
- // ----- We can't delete it before selecting something else -----
- HGDIOBJ hgdiObj = fGDIObject.fObject;
- BOOL bIsStock = fGDIObject.fIsStock;
-
- MakeGDIObject(fGDIObject);
- fPreviousObject = ::SelectObject(fDC, fGDIObject);
-
- // ----- Now we can delete it -----
- if (!bIsStock)
- ::DeleteObject(hgdiObj);
- }
-
- fChanged = FALSE;
- }
- else if (fPreviousObject == NULL) // Never been selected
- {
- FW_ASSERT(fDC == NULL);
- fPreviousObject = ::SelectObject(hdc, fGDIObject);
- FW_ASSERT(fPreviousObject != NULL);
- fDC = hdc;
- }
- // else
- // {
- // FW_ASSERT(FALSE);
- // }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivWinGDIObject::GetObject
- //----------------------------------------------------------------------------------------
- // Returns an object without selecting it into a DC. Mainly used for brushes
-
- HGDIOBJ FW_CPrivWinGDIObject::GetObject(HDC hdc)
- {
- FW_ASSERT(hdc != NULL);
-
- if (fGDIObject == NULL)
- {
- FW_ASSERT(fPreviousObject == NULL);
- FW_ASSERT(fDC == NULL);
- MakeGDIObject(fGDIObject);
- fChanged = FALSE;
- }
- else if (fChanged)
- {
- if (fPreviousObject != NULL)
- {
- FW_ASSERT(fDC == hdc);
- FW_ASSERT(fGDIObject != NULL);
- ::SelectObject(fDC, fPreviousObject);
- fPreviousObject = NULL;
- fDC = NULL;
- }
-
- DeleteGDIObject(fGDIObject);
- MakeGDIObject(fGDIObject);
-
- fChanged = FALSE;
- }
-
- return fGDIObject.fObject;
- }
-
- //========================================================================================
- // class FW_CPrivGDIPen
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIPen::FW_CPrivGDIPen
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGDIPen::FW_CPrivGDIPen() :
- FW_CPrivWinGDIObject()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIPen::~FW_CPrivGDIPen
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGDIPen::~FW_CPrivGDIPen()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIPen::SetPenSize
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIPen::SetPenSize(int width)
- {
- if (fStockObject || fGDIObject == NULL || width != fWidth)
- {
- fStockObject = FALSE;
- fWidth = width;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIPen::SetPenStyle
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIPen::SetPenStyle(FW_EStyleDash dashStyle)
- {
- if (fStockObject || fGDIObject == NULL || dashStyle != fDashStyle)
- {
- fStockObject = FALSE;
- fDashStyle = dashStyle;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIPen::SetPenColor
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIPen::SetPenColor(COLORREF color)
- {
- if (fStockObject || fGDIObject == NULL || color != fColor)
- {
- fStockObject = FALSE;
- fColor = color;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIPen::CreateObject
- //----------------------------------------------------------------------------------------
-
- HGDIOBJ FW_CPrivGDIPen::CreateObject()
- {
- int nStyle = PS_INSIDEFRAME;
- if (fDashStyle != FW_kSolidLine && fWidth <= 1)
- {
- switch (fDashStyle & ~FW_kOpaque)
- {
- default:
- FW_ASSERT(FALSE); // Invalid dash style
- // fall-through
- case FW_kDash:
- nStyle = PS_DASH;
- break;
-
- case FW_kDot:
- nStyle = PS_DOT;
- break;
-
- case FW_kDashDot:
- nStyle = PS_DASHDOT;
- break;
-
- case FW_kDashDotDot:
- nStyle = PS_DASHDOTDOT;
- break;
- }
- }
-
- return ::CreatePen(nStyle, fWidth, fColor);
- }
-
- //========================================================================================
- // class FW_CPrivGDIBrush
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIBrush::FW_CPrivGDIBrush
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGDIBrush::FW_CPrivGDIBrush() :
- FW_CPrivWinGDIObject(),
- fPattern(FW_NEW(FW_CPrivBWPatternRep, (FW_kBlackPat)))
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIBrush::~FW_CPrivGDIBrush
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGDIBrush::~FW_CPrivGDIBrush()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIBrush::SetBrushPattern
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIBrush::SetBrushPattern(const FW_PPrivPattern& pattern)
- {
- if (fSolidColorBrush || fStockObject || fGDIObject == NULL || !pattern.IsSameRepAs(fPattern))
- {
- fStockObject = FALSE;
- fSolidColorBrush = FALSE;
- fPattern = pattern;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIBrush::SetBrushColor
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIBrush::SetBrushColor(COLORREF color)
- {
- if (color != fColor || fStockObject || fGDIObject == NULL || !fSolidColorBrush)
- {
- fStockObject = FALSE;
- fSolidColorBrush = TRUE;
- fColor = color;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIBrush::CreateObject
- //----------------------------------------------------------------------------------------
-
- HGDIOBJ FW_CPrivGDIBrush::CreateObject()
- {
- return fSolidColorBrush ? ::CreateSolidBrush(fColor) : fPattern->WinCreatePatternBrush();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIBrush::GetBrush
- //----------------------------------------------------------------------------------------
- // Called when framing with a brush
-
- HBRUSH FW_CPrivGDIBrush::GetBrush(HDC hdc)
- {
- return (HBRUSH) GetObject(hdc);
- }
-
- //========================================================================================
- // class FW_CPrivGDIFont
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIFont::FW_CPrivGDIFont
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGDIFont::FW_CPrivGDIFont() :
- FW_CPrivWinGDIObject()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIFont::~FW_CPrivGDIFont
- //----------------------------------------------------------------------------------------
-
- FW_CPrivGDIFont::~FW_CPrivGDIFont()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIFont::SetFontName
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIFont::SetFontName(const char* fontName)
- {
- if (fStockObject || fGDIObject == NULL || !FW_PrimitiveStringEqual(fFontName, fontName))
- {
- fStockObject = FALSE;
- FW_PrimitiveStringCopy(fontName, fFontName);
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIFont::SetFontStyle
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIFont::SetFontStyle(FW_FontStyle fontStyle)
- {
- if (fontStyle != fFontStyle || fStockObject || fGDIObject == NULL)
- {
- fStockObject = FALSE;
- fFontStyle = fontStyle;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIFont::SetFontSize
- //----------------------------------------------------------------------------------------
-
- void FW_CPrivGDIFont::SetFontSize(short fontSize)
- {
- if (fontSize != fFontSize || fStockObject || fGDIObject == NULL)
- {
- fStockObject = FALSE;
- fFontSize = fontSize;
- fChanged = TRUE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivGDIFont::CreateObject
- //----------------------------------------------------------------------------------------
-
- HGDIOBJ FW_CPrivGDIFont::CreateObject()
- {
- LOGFONT logFont;
- FW_CMemoryManager::SetMemory(&logFont, sizeof(logFont), 0x00);
-
- HDC screenDC = ::GetDC(NULL);
- logFont.lfHeight = -MulDiv(fFontSize, ::GetDeviceCaps(screenDC, LOGPIXELSY), 72);
- ::ReleaseDC(NULL, screenDC);
-
- FW_PrimitiveStringCopy(fFontName, logFont.lfFaceName);
-
- if (fFontStyle & FW_kItalic)
- logFont.lfItalic = 0xFF;
- if (fFontStyle & FW_kUnderline)
- logFont.lfUnderline = 0xFF;
- if (fFontStyle & FW_kStrikeOut)
- logFont.lfStrikeOut = 0xFF;
- if (fFontStyle & FW_kBold)
- logFont.lfWeight = FW_BOLD;
-
- return ::CreateFontIndirect(&logFont);
- }
-
-
-
- #endif
-